package config

import (
	"common/helper"
	"database/sql"
)

type CfgValidWagedRate struct {
	Id             string  `json:"id" db:"id" cbor:"id"`
	BetAmount      float64 `json:"bet_amount" db:"bet_amount" cbor:"bet_amount"`
	ValidWagedRate float64 `json:"valid_waged_rate" db:"valid_waged_rate" cbor:"valid_waged_rate"`
}

var G_CfgValidWagedRate []CfgValidWagedRate

func AddValidWagedRateSetRow(rows *sql.Rows) {
	var tVal CfgValidWagedRate
	var err error
	err = rows.Scan(&tVal.BetAmount, &tVal.ValidWagedRate)

	if err != nil {
		helper.InfoLog("AddWageSetRow scan err")
		return
	}
	G_CfgValidWagedRate = append(G_CfgValidWagedRate, tVal)
}

func AddValidWagedRateRemove() {
	G_CfgValidWagedRate = []CfgValidWagedRate{}
}

func GetValidWagedRateMul(betAmount float64) float64 {

	for _, value := range G_CfgValidWagedRate {
		if betAmount >= value.BetAmount {
			return value.ValidWagedRate / 100
		}
	}

	return 1.0
}
